clear all
set more off

global chemin "HERE indicated path to the main folder"
cd "$chemin\data"

use final_IHME22, clear
drop if recipient_name == "Unallocated/Unspecified"
* we drop 2019 and 2020 because we don't have bilateral data but just global data
drop if year >= 2019
gen MCP = 0
replace MCP = 1 if year <1993 /* actif jusqu'en 12/1992 inclus */
replace MCP = 1 if year == 1995
replace MCP = 1 if year >1999 & year <2009 /* actif en 1999/2000 et à partir du 01/2001 jusqu'en 12/2008*/
replace MCP = 1 if year >2016 /*actif 01/2017 - 12/2020*/ 


* Intsrument construction
	* Part 1 : probability of receiving FP aid when MCP is not active
	gen aid_pc = (rmh_fp_dah_20_US >0)
	bys recipient_name : egen aid = mean(aid_pc) if MCP == 0
	bys recipient_name : egen FPr = mean(aid)

* instrument 1 : Probability of receiving FP aid when MCP is not active * share channelled through NGO during OBAMA term * policy
	gen instrument1 = FPr * share_NGOUS_Obama * MCP
* instrument 2 : Probability of receiving FP aid when MCP is not active * share channelled through NGO when MCP not active * policy
	gen instrument2 = FPr * share_NGOUS_MCP * MCP

* Creation of controls
	gen lngdppc = ln(GDPpc_r)
	gen lnpopr = ln(pop_r)
	gen laidfp = ln(rmh_fp_dah_20 + ((rmh_fp_dah_20^2 +1)^0.5))
	gen laidUS = ln(rmh_fp_dah_20_US + ((rmh_fp_dah_20_US^2 +1)^0.5))

	gen laidfp2 = ln(rmh_fp_dah_20 + 1)
	gen laidUS2 = ln(rmh_fp_dah_20_US + 1)

	egen id_o = group(donor)
	egen id_dr = group(donor recipient_name)
	egen id_r = group( recipient_name)
	gen fert2 = fertility_r *fertility_r

xtset id_dr year
global controls  lngdppc lnpopr poverty_r
global controls1 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r
global controls2 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r polity2
global controls3 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r polity2 UN_dr 

* controls interacted with FPr*ShareNGOr
foreach i of varlist $controls3 {
	gen `i'_int = `i' * FPr * share_NGOUS_Obama
}


* Definition of different set of controls 
global controlsi  L.lngdppc* L.lnpopr* L.poverty_r*    																				
global controls1i L.lngdppc* L.lnpopr* L.poverty_r* L.life_expectencyfe_r* L.HIV1549_r* L.incidenceHIV_r* L.fert2* L.fertility* L.adofertility* L.maternalmortality_r*
global controls2i L.lngdppc* L.lnpopr* L.poverty_r* L.life_expectencyfe_r* L.HIV1549_r* L.incidenceHIV_r* L.fert2* L.fertility* L.adofertility* L.maternalmortality_r* L.polity2* 
* will exclude the EU and the BMGF because no data on UN vote...
global controls3i L.lngdppc* L.lnpopr* L.poverty_r* L.life_expectencyfe_r* L.HIV1549_r* L.incidenceHIV_r* L.fert2* L.fertility* L.adofertility* L.maternalmortality_r* L.polity2* L.UN_dr* 


/* Baseline results*/
ivreghdfe laidfp $controls2i (laidUS =instrument1 ),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
gen in_sample4 =e(sample)
est store Baseline

ivreghdfe laidfp $controls2i (laidUS =instrument1 ),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
est store Baseline0
ivreghdfe laidfp $controls2i (L1.laidUS =L1.instrument1 ),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
est store Baseline1
ivreghdfe laidfp $controls2i (L2.laidUS =L2.instrument1 ),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
est store Baseline2
ivreghdfe laidfp $controls2i (L3.laidUS =L3.instrument1 ),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
est store Baseline3


* Bilateral reactions
	ivreghdfe laidfp $controls2i (c.L3.laidUS#i.id_o=c.L3.instrument1#i.id_o) if in_s ==1,  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) 
	est store C3
	
	ivreghdfe laidfp $controls2i (c.L2.laidUS#i.id_o=c.L2.instrument1#i.id_o) if in_s ==1,  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) 
	est store C2
	
	ivreghdfe laidfp $controls2i (c.L1.laidUS#i.id_o=c.L1.instrument1#i.id_o) if in_s ==1,  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) 
	est store C1
	
	ivreghdfe laidfp $controls2i (c.laidUS#i.id_o=c.instrument1#i.id_o) if in_s ==1,  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) 
	est store C0
	
	coefplot (Baseline1 C1,label(t-1) msymbol(S) mcolor(green) ciopts(lcolor(green))) ///
		   (Baseline2 C2,label(t-2) msymbol(T) mcolor(ltblue) ciopts(lcolor(ltblue))) , ///
	keep( L.laidUS L2.laidUS   ///
	1.id_o#cL.laidUS 1.id_o#cL2.laidUS ///
	3.id_o#cL.laidUS 3.id_o#cL2.laidUS ///
	5.id_o#cL.laidUS 5.id_o#cL2.laidUS ///
	8.id_o#cL.laidUS 8.id_o#cL2.laidUS ///
	10.id_o#cL.laidUS 10.id_o#cL2.laidUS ///
	11.id_o#cL.laidUS 11.id_o#cL2.laidUS ///
	18.id_o#cL.laidUS 18.id_o#cL2.laidUS ///
	25.id_o#cL.laidUS 25.id_o#cL2.laidUS ///
	 2.id_o#cL.laidUS  2.id_o#cL2.laidUS ///
	 4.id_o#cL.laidUS  4.id_o#cL2.laidUS ///
	 6.id_o#cL.laidUS  6.id_o#cL2.laidUS ///
	 7.id_o#cL.laidUS  7.id_o#cL2.laidUS ///
	 9.id_o#cL.laidUS  9.id_o#cL2.laidUS ///
	12.id_o#cL.laidUS 12.id_o#cL2.laidUS ///
	13.id_o#cL.laidUS 13.id_o#cL2.laidUS ///
	14.id_o#cL.laidUS 14.id_o#cL2.laidUS ///
	15.id_o#cL.laidUS 15.id_o#cL2.laidUS ///
	16.id_o#cL.laidUS 16.id_o#cL2.laidUS ///
	17.id_o#cL.laidUS 17.id_o#cL2.laidUS ///
	19.id_o#cL.laidUS 19.id_o#cL2.laidUS ///
	20.id_o#cL.laidUS 20.id_o#cL2.laidUS ///
	21.id_o#cL.laidUS 21.id_o#cL2.laidUS ///
	22.id_o#cL.laidUS 22.id_o#cL2.laidUS ///
	23.id_o#cL.laidUS 23.id_o#cL2.laidUS ///
	24.id_o#cL.laidUS 24.id_o#cL2.laidUS ///
	)  xline(0)  levels(90)  legend(rows(1)) ///
	graphregion( color(white)) omitted baselevels /// 
	rename( ///
	L.laidUS=L2.laidUS ///
	1.id_o#cL.laidUS=1.id_o#cL2.laidUS ///
	3.id_o#cL.laidUS=3.id_o#cL2.laidUS ///
	5.id_o#cL.laidUS=5.id_o#cL2.laidUS ///
	8.id_o#cL.laidUS=8.id_o#cL2.laidUS ///
	10.id_o#cL.laidUS=10.id_o#cL2.laidUS ///
	11.id_o#cL.laidUS=11.id_o#cL2.laidUS ///
	18.id_o#cL.laidUS=18.id_o#cL2.laidUS ///
	25.id_o#cL.laidUS=25.id_o#cL2.laidUS ///
	 2.id_o#cL.laidUS= 2.id_o#cL2.laidUS ///
	 4.id_o#cL.laidUS= 4.id_o#cL2.laidUS ///
	 6.id_o#cL.laidUS= 6.id_o#cL2.laidUS ///
	 7.id_o#cL.laidUS= 7.id_o#cL2.laidUS ///
	 9.id_o#cL.laidUS= 9.id_o#cL2.laidUS ///
	12.id_o#cL.laidUS=12.id_o#cL2.laidUS ///
	13.id_o#cL.laidUS=13.id_o#cL2.laidUS ///
	14.id_o#cL.laidUS=14.id_o#cL2.laidUS ///
	15.id_o#cL.laidUS=15.id_o#cL2.laidUS ///
	16.id_o#cL.laidUS=16.id_o#cL2.laidUS ///
	17.id_o#cL.laidUS=17.id_o#cL2.laidUS ///
	19.id_o#cL.laidUS=19.id_o#cL2.laidUS ///
	20.id_o#cL.laidUS=20.id_o#cL2.laidUS ///
	21.id_o#cL.laidUS=21.id_o#cL2.laidUS ///
	22.id_o#cL.laidUS=22.id_o#cL2.laidUS ///
	23.id_o#cL.laidUS=23.id_o#cL2.laidUS ///
	24.id_o#cL.laidUS=24.id_o#cL2.laidUS ) ///
	order(L2.laidUS) ///
	coeflabels(L2.laidUS= "Baseline" ///
	 1.id_o#cL2.laidUS="Australia" ///
	 3.id_o#cL2.laidUS="{bf:BMGF}" ///
	 5.id_o#cL2.laidUS="Canada" ///
	 8.id_o#cL2.laidUS="EU" ///
	10.id_o#cL2.laidUS="France" ///
	11.id_o#cL2.laidUS="{bf:Germany}" ///
	18.id_o#cL2.laidUS="{bf:The Netherlands}" ///
	25.id_o#cL2.laidUS="{bf:United Kingdom}" ///
		 2.id_o#cL2.laidUS="Austria" ///
	 4.id_o#cL2.laidUS="Belgium" ///
	  6.id_o#cL2.laidUS="China" ///
	 7.id_o#cL2.laidUS="Denmark" ///
	 9.id_o#cL2.laidUS="Finland" ///
	12.id_o#cL2.laidUS="Greece" ///
	13.id_o#cL2.laidUS="Ireland" ///
	14.id_o#cL2.laidUS="Italy" ///
	15.id_o#cL2.laidUS="Japan" ///
	16.id_o#cL2.laidUS="South Korea" ///
	17.id_o#cL2.laidUS="Luxembourg" ///
	19.id_o#cL2.laidUS="New Zealand" ///
	20.id_o#cL2.laidUS="Norway" ///
	21.id_o#cL2.laidUS="Portugal" ///
	22.id_o#cL2.laidUS="Spain" ///
	23.id_o#cL2.laidUS="Sweden" ///
	24.id_o#cL2.laidUS="Switzerland" )  sort(1,descending)
	graph export "..\output\bilateralresponse.eps", as(eps) preview(on) replace
	
**# Bookmark #6
	* Heterogeneity reaction
					bys donor : egen proximityUS = median(pctagreeus)
			* avec la médiane ou avec une proximité avant le MCP de Bush ? 
			egen groupprox4 = cut(proximityUS), group(4)
			egen groupprox2 = cut(proximityUS), group(2)
			xtset id_dr year
			ivreghdfe laidfp $controls2i (c.L2.laidUS#i.groupprox2=c.L2.instrument1#i.groupprox2),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
			est store P2
			test c.L2.laidUS#i0.groupprox2 = c.L2.laidUS#i1.groupprox2
			ivreghdfe laidfp $controls2i (c.L1.laidUS#i.groupprox2=c.L1.instrument1#i.groupprox2),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
			est store P1
			test c.L.laidUS#i0.groupprox2 = c.L.laidUS#i1.groupprox2
		* Economic competition
			bys recipient_n : egen med = median(economiccompetition_max)
			gen highcompetition = economiccompetition_max > med
			replace highcompetition = . if donor == "BMGF"
			xtset id_dr year
			ivreghdfe laidfp $controls2i (c.L2.laidUS#i.highcompetition=c.L2.instrument1#i.highcompetition),  absorb(id_dr i.yea##i.id_o)  cluster(recipient_name donor) first
			est store E2
			test c.L2.laidUS#i0.highcompetition = c.L2.laidUS#i1.highcompetition
			ivreghdfe laidfp $controls2i (c.L.laidUS#i.highcompetition=c.L.instrument1#i.highcompetition),  absorb(id_dr i.yea##i.id_o)  cluster(recipient_name donor) first
			est store E1
			test c.L.laidUS#i0.highcompetition = c.L.laidUS#i1.highcompetition
		* Abortion recipient
			ivreghdfe laidfp $controls2i (c.L2.laidUS#i.abortionsimple=c.L2.instrument1#i.abortionsimple),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
			est store AR2
			test c.L2.laidUS#i0.abortionsimple = c.L2.laidUS#i1.abortionsimple
			ivreghdfe laidfp $controls2i (c.L.laidUS#i.abortionsimple=c.L.instrument1#i.abortionsimple),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
			est store AR1
			test c.L.laidUS#i0.abortionsimple = c.L.laidUS#i1.abortionsimple
		* Abortion donor
			ivreghdfe laidfp $controls2i (c.L2.laidUS#i.abortiondonor=c.L2.instrument1#i.abortiondonor),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
			est store AD2
			test c.L2.laidUS#i0.abortiondonor = c.L2.laidUS#i1.abortiondonor
			ivreghdfe laidfp $controls2i (c.L.laidUS#i.abortiondonor=c.L.instrument1#i.abortiondonor),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
			est store AD1
			test c.L.laidUS#i0.abortiondonor = c.L.laidUS#i1.abortiondonor
			
			
			coefplot (Baseline1 P1 E1 AR1 AD1,label(t-1) msymbol(S) mcolor(green) ciopts(lcolor(green))) ///
			(Baseline2 P2 E2 AR2 AD2,label(t-2) msymbol(T) mcolor(ltblue) ciopts(lcolor(ltblue))), ///
			graphregion( color(white)) omitted baselevels /// 
			xline(0)  levels(90)  legend(rows(1)) sort(1,descending) ///
		  	keep( L.laidUS L2.laidUS ///
			0.groupprox2#cL.laidUS   1.groupprox2#cL.laidUS ///
			0.groupprox2#cL2.laidUS  1.groupprox2#cL2.laidUS ///
			0.highcompetition#cL.laidUS   1.highcompetition#cL.laidUS ///
			0.highcompetition#cL2.laidUS  1.highcompetition#cL2.laidUS ///
			0.abortionsimple#cL.laidUS   1.abortionsimple#cL.laidUS ///
			0.abortionsimple#cL2.laidUS  1.abortionsimple#cL2.laidUS ///
			0.abortiondonor#cL.laidUS   1.abortiondonor#cL.laidUS ///
			0.abortiondonor#cL2.laidUS  1.abortiondonor#cL2.laidUS ) ///
			rename(L2.laidUS=L.laidUS ///
			0.groupprox2#cL2.laidUS=0.groupprox2#cL.laidUS ///
			1.groupprox2#cL2.laidUS=1.groupprox2#cL.laidUS ///
			0.highcompetition#cL2.laidUS=0.highcompetition#cL.laidUS ///
			1.highcompetition#cL2.laidUS=1.highcompetition#cL.laidUS ///
			0.abortionsimple#cL2.laidUS=0.abortionsimple#cL.laidUS ///
			1.abortionsimple#cL2.laidUS=1.abortionsimple#cL.laidUS ///
			0.abortiondonor#cL2.laidUS=0.abortiondonor#cL.laidUS ///
			1.abortiondonor#cL2.laidUS=1.abortiondonor#cL.laidUS ) ///
			order(L.laidUS 0.highcompetition#cL.laidUS  1.highcompetition#cL.laidUS ///
			0.groupprox2#cL.laidUS  1.groupprox2#cL.laidUS ///
			0.abortionsimple#cL.laidUS  1.abortionsimple#cL.laidUS ///
			0.abortiondonor#cL.laidUS  1.abortiondonor#cL.laidUS) ///
			coeflabels(L.laidUS= "Baseline" ///
			0.groupprox2#cL.laidUS="Low"  1.groupprox2#cL.laidUS="High" ///
			0.highcompetition#cL.laidUS="Low"   1.highcompetition#cL.laidUS="High" ///
			0.abortionsimple#cL.laidUS="Restrictive"   1.abortionsimple#cL.laidUS="Not restrictive" ///
			0.abortiondonor#cL.laidUS="Some restrictions"   1.abortiondonor#cL.laidUS="On request") ///
			headings(0.groupprox2#cL.laidUS = "{bf:US Proximity}" ///
			0.highcompetition#cL.laidUS="{bf:Economic competition}" ///
			0.abortionsimple#cL.laidUS="{bf:Abortion in recipient country}" ///
			0.abortiondonor#cL.laidUS="{bf:Abortion in donor country}" )
			graph export "..\output\heterogeneity.eps", as(eps) preview(on) replace

			
	* Bilateral aid
		gen bilateralaid = rmh_fp_dah_20*(1-sharenonbil_donor)
		gen nonbilateralaid = rmh_fp_dah_20*(sharenonbil_donor)
		gen laidfpbil = ln(bilateralaid + ((bilateralaid^2 +1)^0.5))
		gen laidfpnonbil = ln(nonbilateralaid + ((nonbilateralaid^2 +1)^0.5))
		ivreghdfe laidfpbil $controls2i (L2.laidUS=L2.instrument1) ,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first
		est store H2
		estadd local DRFE "Yes": H2
		estadd local DYFE "Yes": H2
		estadd local Cont "Yes": H2
		ivreghdfe laidfpbil $controls2i (L.laidUS=L.instrument1) ,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first
		est store H1
		estadd local DRFE "Yes": H1
		estadd local DYFE "Yes": H1
		estadd local Cont "Yes": H1
		* Non bilateral aid
		ivreghdfe laidfpnonbil $controls2i (L2.laidUS=L2.instrument1) ,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first
		est store H2bis
		estadd local DRFE "Yes": H2bis
		estadd local DYFE "Yes": H2bis
		estadd local Cont "Yes": H2bis
		ivreghdfe laidfpnonbil $controls2i (L.laidUS=L.instrument1) ,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first
		est store H1bis
		estadd local DRFE "Yes": H1bis
		estadd local DYFE "Yes": H1bis
		estadd local Cont "Yes": H1bis
		

			

	esttab  H1* H2*, starlevels(* 0.10 ** 0.05 *** 0.01) keep(L.laidUS L2.laidUS)   order(L2.laidUS L.laidUS) 
	
	esttab  H1 H2 H1bis H2bis  /*OLS*/ using "..\output\channel.tex" ,  replace ///
	keep(L.laidUS L2.laidUS)  ///
	b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
	  substitute($ \$ ) /// /* Formatting label */
	coeflabel(L.laidUS "USFPaid\$_{rt-1}$" ///
	L2.laidUS "USFPaid\$_{rt-2}$"  ) ///
	nonumber compress nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
	mgroups("Bilateral channel" "Non bilateral channel" , pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles ///
	scalars("N Obs." "df_a_nested Donor-recipient pair" "N_clust Recipient" "widstat K-P. F-Stat" ///
	"DRFE Donor-Recipient FE" ///
	"DYFE Donor-Year FE" ///
	"Cont Controls\$ _{rt-1}$")  sfmt(a3) 



**# Bookmark #1
/* Terms effect */ 
preserve
	ivreghdfe laidfp $controls2i  (L2.laidUS=L2.instrument1) if  in_s == 1 &  (year <2001)  ,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first
	ivreghdfe laidfp $controls2i  (L.laidUS=L.instrument1) if  in_s == 1 &  (year <2001)  ,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first

	ivreghdfe laidfp $controls2i  (L2.laidUS=L2.instrument1) if  in_s == 1 &  (year >1992 & year <2009)  ,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first
	est store CB2
	estadd local DRFE "Yes": CB2
	estadd local DYFE "Yes": CB2
	estadd local Cont "Yes": CB2
	ivreghdfe laidfp $controls2i  (L2.laidUS=L2.instrument1) if  in_s == 1 &   year >2000 & year <2017,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor )  first
	est store BO2
	estadd local DRFE "Yes": BO2
	estadd local DYFE "Yes": BO2
	estadd local Cont "Yes": BO2
	ivreghdfe laidfp $controls2i  (L2.laidUS=L2.instrument1) if   in_s == 1 &  year >2008,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor )  first
	est store OT2
	estadd local DRFE "Yes": OT2
	estadd local DYFE "Yes": OT2
	estadd local Cont "Yes": OT2

	ivreghdfe laidfp $controls2i  (L.laidUS=L.instrument1) if  in_s == 1 &  (year >1992 & year <2009)  ,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first
	est store CB1
	estadd local DRFE "Yes": CB1
	estadd local DYFE "Yes": CB1
	estadd local Cont "Yes": CB1
	ivreghdfe laidfp $controls2i  (L.laidUS=L.instrument1) if  in_s == 1 &   year >2000 & year <2017,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor )  first
	est store BO1
	estadd local DRFE "Yes": BO1
	estadd local DYFE "Yes": BO1
	estadd local Cont "Yes": BO1
	ivreghdfe laidfp $controls2i  (L.laidUS=L.instrument1) if   in_s == 1 &  year >2008,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor )  first
	est store OT1
	estadd local DRFE "Yes": OT1
	estadd local DYFE "Yes": OT1
	estadd local Cont "Yes": OT1
	* 2SLS *
	esttab  CB2 CB1 BO2 BO1 OT2 OT1, starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) keep(  L2.laidUS L.laidUS )   
	esttab CB2 CB1 BO2 BO1 OT2 OT1  using "..\output\admin.tex" ,  replace ///
		drop(* )  ///
		b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{*}$} 0.01) /// /* number format and stars */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  ///
		mgroups("1993-2000" "2001-2016" "2009-2019", pattern(1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles 
	esttab  CB1 CB2 BO1 BO2 OT1 OT2 using "..\output\admin.tex" ,  append ///
		keep( L.laidUS L2.laidUS )   ///
		b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		  substitute($ \$ ) /// /* Formatting label */
		coeflabel(L.laidUS "USFPaid\$_{rt-1}$" ///
		L2.laidUS "USFPaid\$_{rt-2}$"  ) ///
		nonumber compress nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		scalars("N Obs." "df_a_nested Donor-recipient pair" "N_clust1 Recipient" "widstat K-P. F-Stat" ///
		"DRFE Donor-Recipient FE" ///
		"DYFE Donor-Year FE" ///
		"Cont Controls\$_{rt-1}$")  sfmt(a3) nomtitles
restore

**# Bookmark #4
/* Aggregation of flows for different kind of reaction */ 
	* as only one donor
		preserve 
		collapse (sum) rmh_fp_dah_20 (mean) in_sample laidUS instrument1 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r polity2 UN_dr   FPr share_NGOUS_Obama, by(year wb_location_id recipient_name id_r)
		gen laidfp = ln(rmh_fp_dah_20 + ((rmh_fp_dah_20^2 +1)^0.5))
		foreach i of varlist $controls2 {
			gen `i'_int = `i' * FPr * share_NGOUS_Obama
		}
		xtset id_r year
		ivreghdfe laidfp $controls2i (L2.laidUS=L2.instrument1) if in_s == 1,  absorb(id_r i.year)  cluster(recipient_name ) first
		est store A2
		estadd local RFE "Yes": A2
		estadd local DYFE "Yes": A2
		estadd local Cont "Yes": A2
		estadd local Cont2 "No": A2
		ivreghdfe laidfp $controls2i (L.laidUS=L.instrument1) if in_s == 1,  absorb(id_r i.year)  cluster(recipient_name ) first
		est store A1
		estadd local RFE "Yes": A1
		estadd local DYFE "Yes": A1
		estadd local Cont "Yes": A1
		estadd local Cont2 "No": A1
		ivreghdfe laidfp $controls2i (L3.laidUS=L3.instrument1) if in_s == 1,  absorb(id_r i.year)  cluster(recipient_name ) first
		est store A3
		estadd local RFE "Yes": A3
		estadd local DYFE "Yes": A3
		estadd local Cont "Yes": A3
		estadd local Cont2 "No": A3
		ivreghdfe laidfp $controls2i (laidUS=instrument1) if in_s == 1,  absorb(id_r i.year)  cluster(recipient_name ) first
		est store A0
		estadd local RFE "Yes": A0
		estadd local DYFE "Yes": A0
		estadd local Cont "Yes": A0
		estadd local Cont2 "No": A0
restore
	
	* as only one recipient
		preserve 
		global controls2l L.lngdppc L.lnpopr L.poverty_r L.life_expectencyfe_r L.incidenceHIV_r L.HIV1549_r L.fert2 L.fertility_r L.adofertility_r L.maternalmortality_r L.polity2
		collapse (sum) rmh_fp_dah_20 (mean) in_sample laidUS instrument1 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r polity2 UN_dr   FPr share_NGOUS_Obama, by(year donor id_o)
		gen laidfp = ln(rmh_fp_dah_20 + ((rmh_fp_dah_20^2 +1)^0.5))
		xtset id_o year
		ivreghdfe laidfp $controls2l (L2.laidUS=L2.instrument1) ,  absorb(id_o ) robust  first
		est store AR2
		estadd local RFE "Yes": AR2
		estadd local DYFE "No": AR2
		estadd local Cont "No": AR2
		estadd local Cont2 "Yes": AR2
		ivreghdfe laidfp $controls2l (L.laidUS=L.instrument1) ,  absorb(id_o )  robust first
		est store AR1
		estadd local RFE "Yes": AR1
		estadd local DYFE "No": AR1
		estadd local Cont "No": AR1
		estadd local Cont2 "Yes": AR1
		ivreghdfe laidfp $controls2l (L3.laidUS=L3.instrument1) ,  absorb(id_o )  robust  first
		est store AR3
		estadd local RFE "Yes": AR3
		estadd local DYFE "No": AR3
		estadd local Cont "No": AR3
		estadd local Cont2 "Yes": AR3		
		ivreghdfe laidfp $controls2l (laidUS=instrument1) ,  absorb(id_o )  robust  first
		est store AR0
		estadd local RFE "Yes": AR0
		estadd local DYFE "No": AR0
		estadd local Cont "No": AR0
		estadd local Cont2 "Yes": AR0
	restore
	
	
	esttab A0 A1 A2 A3 AR0 AR1 AR2 AR3 using "..\output\aggregate.tex" ,  replace ///
		drop(* )  ///
		b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mtitles("(1)" "(2)" "(3)" "(4)" "(5)" "(6)" "(7)" "(8)")
	esttab A0 A1 A2 A3 AR0 AR1 AR2 AR3   using "..\output\aggregate.tex" ,  append ///
		drop(* )  ///
		b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{*}$} 0.01) /// /* number format and stars */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  ///
		mgroups("As one donor" "As one recipient" , pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles
	esttab A0 A1 A2 A3 AR0 AR1 AR2 AR3   using "..\output\aggregate.tex" ,  append ///
		drop(* )  ///
		b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{*}$} 0.01) /// /* number format and stars */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  ///
		mgroups("Dep. Var.: FPA\$_{rt}$" "Dep. Var.: FPA\$_{dt}$" , pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles
	esttab A0 A1 A2 A3 AR0 AR1 AR2 AR3 using "..\output\aggregate.tex" ,  append ///
	keep(laidUS L.laidUS L2.laidUS L3.laidUS)  ///
	b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
	  substitute($ \$ ) /// /* Formatting label */
	coeflabel(L3.laidUS "USFPAid\$_{(r)t-3}$" ///
		L2.laidUS "USFPAid\$_{(r)t-2}$" ///
		L.laidUS "USFPAid\$_{(r)t-1}$" ///
		laidUS  "USFPAid\$_{(r)t}$"	) ///
	nonumber compress nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
	scalars("N Obs." "widstat K-P. F-Stat"  ///
	"RFE Recipient or Donor FE" ///
	"DYFE Year FE" ///
	"Cont Controls\$_{rt-1}$" ///
	"Cont2 Controls\$_{t-1}$")  sfmt(a3) nomtitles
